package com.wgts.wgts.mvp.view.activity.awardmore;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.wgts.wgts.R;
import com.wgts.wgts.base.BaseActivity;
import com.wgts.wgts.control.dialog.RuleDialogFragment;
import com.wgts.wgts.dagger.ComponentHolder;
import com.wgts.wgts.dagger.component.DaggerAwardMoreActivityComponent;
import com.wgts.wgts.dagger.module.AwardMoreActivityModule;
import com.wgts.wgts.mvp.presenter.IAwardMoreActivityPresenter;
import com.wgts.wgts.mvp.view.IAwardMoreActivityView;
import com.wgts.wgts.mvp.view.activity.guessing.GuessingActivity;
import com.wgts.wgts.mvp.view.activity.guessing.MyGuessingActivity;
import com.wgts.wgts.mvp.view.activity.login.LoginActivity;

import com.wgts.wgts.mvp.view.activity.webactivity.WebActivity;
import com.wgts.wgts.netmodle.resp.AwardMoreListEntity;
import com.wgts.wgts.tools.AppInfor;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/*
 *
 *
 *   data:2018/10/919:03
 *
 */public class AwardMoreActivity extends BaseActivity implements IAwardMoreActivityView {
    @BindView(R.id.award_more_image)
    ImageView awardMoreImage;
    @BindView(R.id.award_more_recycle)
    RecyclerView awardMoreRecycle;
    @BindView(R.id.award_more_back)
    ImageView awardMoreBack;
    @BindView(R.id.award_more_ly)
    LinearLayout awardMoreLy;
    @BindView(R.id.alpha_back)
    ImageView alphaBack;
    @BindView(R.id.award_rule_ly)
    LinearLayout awardRuleLy;

    private AwardRecycleAdapter adapter;
    private List<AwardMoreListEntity> moreListEntities;

    @Inject
    IAwardMoreActivityPresenter presenter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.award_more_activity);
        ButterKnife.bind(this);
        initView();
    }

    @Override
    public void init() {
        DaggerAwardMoreActivityComponent
                .builder()
                .appComponent(ComponentHolder.getInstance().getAppComponent())
                .awardMoreActivityModule(new AwardMoreActivityModule(this))
                .build()
                .inject(this);
        moreListEntities = new ArrayList<>();
    }

    private void initView() {
        //refreshLayout.setEnableRefresh(false);
        awardMoreRecycle.setLayoutManager(new LinearLayoutManager(this));
        adapter = new AwardRecycleAdapter(this, moreListEntities);
        awardMoreRecycle.setAdapter(adapter);
        adapter.setOnClickListener(new AwardRecycleAdapter.OnClickListener() {
            @Override
            public void onClick(View view, int i) {
//                Intent intent = new Intent(AwardMoreActivity.this, MoreMoreGoodInfoActivity.class);
//                intent.putExtra(MoreMoreGoodInfoActivity.DRAWID, moreListEntities.get(i).drawId);
//                intent.putExtra(MoreMoreGoodInfoActivity.TYPE, MoreMoreGoodInfoActivity.MORE_MORE_LIST);
//                startActivityForResult(intent, 0);
            }
        });
        load();
        presenter.initList();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data){
        super.onActivityResult(requestCode, resultCode, data);
        presenter.initList();
    }

    @OnClick({R.id.award_more_back, R.id.award_more_ly, R.id.alpha_back, R.id.award_rule_ly})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.award_more_back:
                finish();
                break;
            case R.id.award_more_ly:
                if (AppInfor.getInstance().getRefreshToken() != null && !AppInfor.getInstance().getRefreshToken().equals("")){
                    Intent intent = new Intent(AwardMoreActivity.this, MyAwardMoreActivity.class);
                    startActivity(intent);
                }else {
                    Intent intent = new Intent(AwardMoreActivity.this, LoginActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.alpha_back:
                finish();
                break;
            case R.id.award_rule_ly:
                Intent intent1 = new Intent(AwardMoreActivity.this, WebActivity.class);
                intent1.putExtra(WebActivity.TITLE, "规则");
                intent1.putExtra(WebActivity.ACTION_URL, "https://wap.mohuyoupin.com/jdd_rule.html");
                startActivity(intent1);
//                RuleDialogFragment fragment = RuleDialogFragment.getAwardDialogFragment("展示的信息", RuleDialogFragment.AWARD);
//                fragment.show(getSupportFragmentManager(), "AwardDialog");
                break;
        }
    }

    @Override
    public void onError(int status, String msg) {

    }

    @Override
    public void initList(List<AwardMoreListEntity> listEntities, boolean noMore) {
        /*adapter.setNoMore(noMore);
        if (noMore) {
            refreshLayout.setEnableLoadmore(false);
        } else {
            refreshLayout.setEnableLoadmore(true);
        }*/
        moreListEntities.clear();
        moreListEntities.addAll(listEntities);
        adapter.notifyDataSetChanged();
    }

    @Override
    public void loadMore(List<AwardMoreListEntity> listEntities, boolean noMore) {
        /*refreshLayout.finishLoadmore();
        adapter.setNoMore(noMore);
        if (noMore) {
            refreshLayout.setEnableLoadmore(false);
        } else {
            refreshLayout.setEnableLoadmore(true);
        }
        moreListEntities.addAll(listEntities);
        adapter.notifyDataSetChanged();*/
    }

    private void load() {
        /*refreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() {
            @Override
            public void onLoadmore(RefreshLayout refreshlayout) {
                presenter.loadMore();
            }
        });*/
    }

}
